﻿Imports Microsoft.Win32
Imports FlipCSSLib
 Class MainWindow
    Private Sub Window_MouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs)
        Me.DragMove()
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnTran.Click
        dispatcherTimer.Start()

        Me.txtout.Text = FlipCSS.Flip(txtinput.Text)

        txtout.FlowDirection = Windows.FlowDirection.LeftToRight

    End Sub

    Private Sub Button1_Click_1(sender As Object, e As RoutedEventArgs) Handles btnClose.Click
        Application.Current.Shutdown()
    End Sub

    Private Sub btnfolder_Click(sender As Object, e As RoutedEventArgs) Handles btnfolder.Click
        Dim f As New OpenFileDialog
        f.Title = "اختر ملف واحد وسختار البرنامج تلقائيا بقية الملفات"
        If f.ShowDialog = True Then
            dispatcherTimer.Start()
            Dim dir As String = IO.Path.GetDirectoryName(f.FileName)
            MessageBox.Show(dir)

            FileFlip(dir)


            Dim directories = My.Computer.FileSystem.GetDirectories(dir)
            For Each direcory In directories
                FileFlip(direcory)
            Next
            MessageBox.Show("تمت العملية بنجاح")
        End If

    End Sub

    Sub FileFlip(dir As String)
        Dim files = My.Computer.FileSystem.GetFiles(dir)
        For Each file In files
            If file.ToLower.EndsWith(".css") Then
                My.Computer.FileSystem.WriteAllText(file, FlipCSS.Flip(My.Computer.FileSystem.ReadAllText(file)), False)
            End If
        Next
    End Sub

    WithEvents dispatcherTimer As New System.Windows.Threading.DispatcherTimer With {.Interval = New TimeSpan(0, 0, 0, 0, 200)}
    Dim counter As Byte = 1
    Dim OrginalBrush As New SolidColorBrush(ColorConverter.ConvertFromString("#FFECC69A"))

    Private Sub dispatcherTimer_Tick(sender As Object, e As EventArgs) Handles dispatcherTimer.Tick
   

        Select Case counter
            Case 1
                Ellipse1.StrokeThickness = 3
                Ellipse1.Stroke = New SolidColorBrush(Colors.Orange)
            Case 2
                Me.el1.Fill = New System.Windows.Media.SolidColorBrush(Windows.Media.Colors.Red)

            Case 3
                Me.el2.Fill = New System.Windows.Media.SolidColorBrush(Windows.Media.Colors.Red)
                Me.el1.Fill = OrginalBrush
            Case 4
                Me.el2.Fill = OrginalBrush
            Case 5
                Ellipse2.StrokeThickness = 3
                Ellipse2.Stroke = New SolidColorBrush(Colors.Orange)
            Case Else
                dispatcherTimer.Stop()
                counter = 0
                Ellipse1.StrokeThickness = 0
                Ellipse2.StrokeThickness = 0
        End Select

        counter += 1
    End Sub




End Class
